<?php
header('Content-Type:text/html;charset=utf-8');
function curl_request($url,$post='',$cookie='', $returnCookie=0){
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)');
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($curl, CURLOPT_AUTOREFERER, 1);
    curl_setopt($curl, CURLOPT_REFERER, "http://XXX");
    if($post) {
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post));
    }
    if($cookie) {
        curl_setopt($curl, CURLOPT_COOKIE, $cookie);
    }
    curl_setopt($curl, CURLOPT_HEADER, $returnCookie);
    curl_setopt($curl, CURLOPT_TIMEOUT, 10);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $data = curl_exec($curl);
    if (curl_errno($curl)) {
        return curl_error($curl);
    }
    curl_close($curl);
    if($returnCookie){
        list($header, $body) = explode("\r\n\r\n", $data, 2);
        preg_match_all("/Set\-Cookie:([^;]*);/", $header, $matches);
        $info['cookie']  = substr($matches[1][0], 1);
        $info['content'] = $body;
        return $info;
    }else{
        return $data;
    }
}
$out_trade_no = date("YmdHis").mt_rand(100,999);
$notify_url = "https://www.baidu.com/";
$total_fee = 1.00;
$api_url = "http://8.136.97.177:8020/api/gateway/create";
$mch_secret = "jJHmqmQqAytf3QAShp6xH8yoXqXTWH8X";
$data = [
    "mch_id" =>"1001140",
    "child_type" =>"H5",
    "out_trade_no" =>$out_trade_no,
    "pay_type" =>"PERSONAL_RED_PACK",
    "total_fee" =>$total_fee,
    "notify_url" =>$notify_url,
    "timestamp" => time(),
];

$sign_str = "child_type=".$data["child_type"]."&mch_id=".$data["mch_id"]."&mch_secret=".$mch_secret."&notify_url=".urlencode($data["notify_url"])."&out_trade_no=".$data["out_trade_no"]."&pay_type=".$data["pay_type"]."&timestamp=".$data["timestamp"]."&total_fee=".$data["total_fee"];
$sign = strtoupper(md5($sign_str));

$data["sign"] = $sign;

$result = curl_request($api_url,$data);
echo "<pre>";
print_r($result);